package com.lmj.eurekaclient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
@RestController
public class EurekaClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaClientApplication.class, args);
    }


    @Autowired
    private RestTemplate restTemplate;

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    @Value("${server.port}")
    String port;
    @RequestMapping("/hi")
    public  String hi(String name){

        return "hello " + name + "from port:"+port;
    }

    @RequestMapping("/zhi")
    public  String zhi(String name){
        return restTemplate.getForObject("http://SERVICE-MIYA/miya", String.class);
        //return "hello " + name + "from port:"+port;
    }

    @RequestMapping("/info")
    public String info(){
        System.out.println("calling trace service-hi ");
        return "i'm service-hi";

    }

}
